//方法二
//在原链表的每一个节点后接上该节点的新拷贝节点

#include<iostream>

using namespace std;


// Definition for a Node.
class Node {
public:
    int val;
    Node* next;
    Node* random;
    
    Node(int _val) {
        val = _val;
        next = NULL;
        random = NULL;
    }
};


class Solution {
public:
    Node* copyRandomList(Node* head) 
    {
        if(head==nullptr)
        {
            return nullptr;
        }
        Node* cur=head;
        Node* next=head->next;
        while(cur)
        {
            cur->next=new Node(cur->val);
            cur->next->next=next;
            cur=cur->next->next;
            if(next)
            {
                next=next->next;
            }
        }
        Node* _head=head->next;
        Node* _cur=_head;
        cur=head;
        while(cur)
        {
            _cur->random=cur->random==nullptr?nullptr:cur->random->next;
            cur=cur->next->next;
            if(_cur->next)
            {
                _cur=_cur->next->next;
            }
        }
        cur=head->next->next;
        _cur=_head;
        while(cur)
        {
            _cur->next=cur->next;
            cur=cur->next->next;
        }
        return _head;
    }
};

int main()
{

    return 0;
}